<template>
    <view>
        <u-navbar :autoBack="true" :safeAreaInsetTop="true" :placeholder="true" bgColor="#FFF" :fixed="true">
            <view slot="left" style="display: flex;">
                <u-icon name="arrow-left" size="28"></u-icon>
            </view>
            <view slot="center"
                style=" line-height: 27px; text-align: center; color: #000;width: 100%;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;margin-left: 20rpx">
                {{ title }}
            </view>
        </u-navbar>
        <view style="padding: 40rpx;">
            <view style="display: flex;justify-content: space-between;">
                <view
                    style="width: 43%;padding: 20rpx;background: #F6FFF7;display: flex;justify-content: space-between;align-items: center;border-radius: 10px;">
                    <view>
                        <view style="font-size: 18px;">{{ questionNum.total || 0 }}</view>
                        <view style="font-size: 14px;color: #666666;margin-top: 20rpx;">{{ type == 1 ? '全部错题' : '全部收藏'
                            }}</view>
                    </view>
                    <image
                        :src="type == 1 ? '/questionBankMarket/static/allWrong.svg' : '/questionBankMarket/static/allCollection.svg'"
                        style="width: 170rpx;height: 170rpx;">
                    </image>
                </view>
                <view
                    style="width: 43%;padding: 20rpx;background: #FFF2F2;display: flex;justify-content: space-between;align-items: center;border-radius: 10px;">
                    <view>
                        <view style="font-size: 18px;">{{ questionNum.today || 0 }}</view>
                        <view style="font-size: 14px;color: #666666;margin-top: 20rpx;">{{ type == 1 ? '今日错题' : '今日收藏'
                            }}</view>
                    </view>
                    <image
                        :src="type == 1 ? '/questionBankMarket/static/todayWrong.svg' : '/questionBankMarket/static/todayCollection.svg'"
                        style="width: 170rpx;height: 170rpx;">
                    </image>
                </view>
            </view>
            <view style="display: flex;justify-content: space-between;align-items: center;margin-top: 40rpx;"
                v-for="(item, index) in question" :key="index" @click="onJump(item)">
                <view>
                    {{ onChangeDict(item.itemType,
                        mapDictCodesData.allQuestionType) }}（{{ item.num || 0 }}）
                </view>
                <view style="display: flex;">
                    <text>查看</text>
                    <u-icon name="arrow-right" size="20"></u-icon>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
import { questionTabPracticeItemType, questionTabPracticeItemTypeHeader } from '../services/PracticeTestingService';
import { listMyExerciseItemCount, listMyExerciseItemType } from '../services/QuestionBankService';
import { mapDictCodes } from '../services/ServerService';
import { getArrObjectByProperty } from '../utils/PrjUtils';

export default {
    data() {
        return {
            marketId: '',
            title: "",
            question: [],
            type: '', // 题型：错题1 收藏2
            questionNum: {},
            flag: false,
            practiceUuid: '',
            tableName:'',
            tabType:"",
            mapDictCodesData:[],
        }
    },
    onLoad(option) {
        this.marketId = option.marketId
        this.title = option.title
        this.type = option.type
        this.practiceUuid = option.practiceUuid
        this.flag = option.flag
        this.tableName = option.tableName
        this.tabType=option.tabType=="practice"?1:2
        this.onMapDictCodes()
        this.onListMyExerciseItemCount()
        this.onlistMyExerciseItemType()
        console.log("onLoad")
    },
    onShow(){
        console.log("onShow")
        // this.onlistMyExerciseItemType()
    },
    computed: {},
    methods: {
        onMapDictCodes() {
            mapDictCodes('allQuestionType').then(res => {
                this.mapDictCodesData = res||[]
            })
        },
        onChangeDict(val, dict) {
            console.log(val, 'vallllll');
            if (dict&&Array.isArray(dict)) {
                return getArrObjectByProperty(dict, 'value', val)?.label || ''
            }
            else{
                return '--'
            }
        },
        onListMyExerciseItemCount() {
            if (this.flag) {
                questionTabPracticeItemTypeHeader({ type: this.type, practiceUuid: this.practiceUuid,tabType:this.tabType }).then(res => {
                    this.questionNum = res
                })
            } else {
                listMyExerciseItemCount({ marketId: this.marketId, type: this.type }).then(res => {
                    this.questionNum = res
                })
            }

        },
        onlistMyExerciseItemType() {
            if (this.flag) {
                questionTabPracticeItemType({ type: this.type, practiceUuid: this.practiceUuid,tabType:this.tabType}).then(res => {
                    this.question = res
                })
            } else {
                listMyExerciseItemType({ marketId: this.marketId, type: this.type }).then(res => {
                    this.question = res
                })
            }

        },
        onJump(item) {
            if (this.flag) {
                uni.navigateTo({
                    url: '/pages/practiceTesting/exercisesPage?practiceUuid=' + this.practiceUuid + '&isCollection=true&exerciseType=' + this.type + '&collection=true&tableName=' + this.tableName+'&itemType='+item.itemType
                })
            } else {
                uni.navigateTo({
                    url: '/pages/practiceTesting/exercisesPage?practiceUuid=' + this.marketId + '&isCollection=true&exerciseType=' + this.type + '&collection=true&itemType=' + item.itemType + '&tableName=FuncItemMarket'
                })
            }

        }
    },
    // onShow() {

    // },

}
</script>

<style lang="scss">
page {
    background: #ffffff !important;
}
</style>